use crate::dto::{Empty, ResponseBody};
use apikit::ApiErrorItem;
use axum::response::IntoResponse;

pub mod form;
pub mod header;
pub mod json;
pub mod multipart;
pub mod path;
pub mod query;
pub mod ws;

pub fn error_to_response<E>(e: E) -> axum::response::Response
where
    ApiErrorItem: From<E>,
{
    let error_item = ApiErrorItem::from(e);
    (
        axum::http::StatusCode::from_u16(error_item.status).unwrap_or_default(),
        axum::Json(ResponseBody::<Empty> {
            code: error_item.code,
            data: Empty,
            message: error_item.cause,
        }),
    )
        .into_response()
}
